<template>
  <div class="page wxshare">
    <van-button
      class="default"
      @click="changeInfo"
      type="primary"
    >修改分享内容</van-button>
    <van-button
      class="default"
      @click="adjustShare(false)"
      type="primary"
    >禁止微信分享</van-button>
    <van-button
      class="default"
      @click="adjustShare(true)"
      type="primary"
    >重新开启微信分享</van-button>
    <van-button
      class="default"
      @click="backHome"
      type="primary"
    >返回首页</van-button>
  </div>
</template>

<script>
import wx from 'weixin-js-sdk'
import util from './../util/index'

export default {
  name: 'answer',
  data () {
    return {
      list: [],
      loading: false,
      finished: false
    }
  },
  methods: {
    changeInfo () {
      this.$toast('修改分享内容成功');
      util.changeShareInfo(wx);
    },
    adjustShare (flag) {
      //  禁止微信分享
      if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
          document.addEventListener('WeixinJSBridgeReady', wx.onBridgeReady, false);
        } else if (document.attachEvent) {
          document.attachEvent('WeixinJSBridgeReady', wx.onBridgeReady);
          document.attachEvent('onWeixinJSBridgeReady', wx.onBridgeReady);
        }
      } else {
        flag ? WeixinJSBridge.call('showOptionMenu') : WeixinJSBridge.call('hideOptionMenu')
      }
    },
    backHome () {
      this.$router.replace({ name: 'home' });
    }
  }
}
</script>

<style lang="less" scoped>
.wxshare {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.default {
  margin-bottom: 0.5rem;
  width: 80%;
}
</style>

